package com.zrwl.poscloud.core.restapi.admin.baseInfo;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.xo.service.AdminService;
import com.zrwl.poscloud.xo.vo.AdminVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zrwl.poscloud.xo.service.CallProductConfigService;
import com.zrwl.poscloud.xo.vo.CallProductConfigVO;

import java.util.Date;

/**
 * 通话产品配置 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-06-09
 */
@RestController
@Api(value = "通话产品配置相关接口", tags = {"通话产品配置相关接口"})
@RequestMapping("/callProductConfig")
@Slf4j
public class CallProductConfigRestApi {
    @Autowired
    private CallProductConfigService callProductConfigService;
    @Autowired
    private AdminService adminService;
    @AuthorityVerify
    @ApiOperation(value = "获取通话产品配置列表", notes = "获取通话产品配置列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody CallProductConfigVO callProductConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取通话产品配置列表: {}", callProductConfigVO);
        callProductConfigVO.setCompanyUid(adminService.getMe().getCompanyUid());
        return ResultUtil.successWithData(callProductConfigService.getPageList(callProductConfigVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取通话产品配置列表", notes = "获取通话产品配置列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody CallProductConfigVO callProductConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取通话产品配置列表: {}", callProductConfigVO);
        callProductConfigVO.setCompanyUid(adminService.getMe().getCompanyUid());
        return ResultUtil.successWithData(callProductConfigService.getAllList(callProductConfigVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增通话产品配置")    @ApiOperation(value = "新增通话产品配置", notes = "新增通话产品配置", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody CallProductConfigVO callProductConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增通话产品配置: {}", callProductConfigVO);
        callProductConfigVO.setCompanyUid(adminService.getMe().getCompanyUid());
        return callProductConfigService.add(callProductConfigVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改通话产品配置")    @ApiOperation(value = "修改通话产品配置", notes = "修改通话产品配置", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody CallProductConfigVO callProductConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改通话产品配置: {}", callProductConfigVO);
        return callProductConfigService.edit(callProductConfigVO);
    }
    @AuthorityVerify
    @OperationLogger(value = "获取自动生成产品编号")
    @ApiOperation(value = "获取自动生成产品编号", notes = "获取自动生成产品编号", response = String.class)
    @PostMapping("/getAutoProductCode")
    public String getAutoProductCode() throws Exception {
        log.info("获取自动生成产品编号" + new Date());
        return ResultUtil.successWithData(callProductConfigService.getAutoProductCode());
    }
    @AuthorityVerify
    @OperationLogger(value = "删除通话产品配置")    @ApiOperation(value = "删除通话产品配置", notes = "删除通话产品配置", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody CallProductConfigVO callProductConfigVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除通话产品配置: {}", callProductConfigVO);
        return callProductConfigService.delete(callProductConfigVO);
    }

}
